package com.wangyk.user.service.impl;

import com.wangyk.rabbitmqcommon.VO.ResultVO;
import com.wangyk.rabbitmqcommon.model.user.UserInfo;
import com.wangyk.rabbitmqcommon.utils.ResultVOUtils;
import com.wangyk.user.repository.UserRepository;
import com.wangyk.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService
{
    @Autowired
    private UserRepository userRepository;

    @Override
    public ResultVO findByOpenid(String openId)
    {
        UserInfo userInfo = userRepository.findByOpenid(openId);
        ResultVO resultVO=new ResultVO();
        resultVO.setData(userInfo);
        return ResultVOUtils.success(resultVO);
    }

    @Override
    public ResultVO addUser(UserInfo userInfo)
    {
        userRepository.save(userInfo);
        log.debug("userInfo.getId():"+userInfo.getId());
        ResultVO resultVO=new ResultVO();
        resultVO.setData(userInfo);
        return resultVO;
    }

    @Override
    public ResultVO findLikeOpenid(String openId)
    {
        log.info("serviceImpl openId:"+openId);
        List<UserInfo> userInfoList = userRepository.findLikeOpenid(openId);
        ResultVO resultVO=new ResultVO();
        resultVO.setData(userInfoList);
        return resultVO;
    }
}
